<template>
  <a-modal v-model="visible" :width="1180" title="商品选择" @ok="batchSelectItem">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="12" :lg="12" :md="12" :sm="24">
            <a-form-item label="标题">
              <a-input placeholder="请输入标题" v-model="queryParam.title"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="商品编号">
              <a-input placeholder="请输入商品编号" v-model="queryParam.itemCode"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="商品货号">
              <a-input placeholder="请输入商品货号" v-model="queryParam.code"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="12" :lg="12" :md="12" :sm="24">
            <a-form-item label="分类">
              <div style="display:flex;align-items: center;">
                <a-select v-model="queryParam.pcategoryId" placeholder="请选择一级分类" @change="getcateId2sChange">
                  <a-select-option v-for="(item,index) in cateId1s" :key="index" :value="item.id">
                    {{ item.name }}
                  </a-select-option>
                </a-select>
                <a-divider type="vertical" />
                <a-select v-model="queryParam.categoryId" placeholder="请选择二级分类">
                  <a-select-option v-for="(item,index) in cateId2s" :key="index" :value="item.id">
                    {{ item.name }}
                  </a-select-option>
                </a-select>
              </div>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>

            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <a-table ref="table" size="small" bordered rowKey="itemCode" :columns="columns" :dataSource="dataSource" :pagination="ipagination"
        :loading="loading" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type:selectionType}"
        class="j-table-force-nowrap" @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="55px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="selectItem(record)" v-if="selectionType=='radio'">选择</a>
        </span>

      </a-table>
    </div>

  </a-modal>
</template>

<script>
import { getAction, postAction, putAction } from '@/api/manage'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/MyJeecgListMixin'


export default {
  name: 'GmsZyGoodRef',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
  },
  data () {
    return {
      pageCheckedKeys: [],
      noPageCheckedKeys: [],
      pageCheckedRows: [],
      noPageCheckedRows: [],
      visible: false,
      description: '商品选择',
      // 表头
      columns: [
        {
          title: '商品编号',
          align: "center",
          dataIndex: 'itemCode'
        },
        {
          title: '商品货号',
          align: "center",
          dataIndex: 'code'
        },
        {
          title: '标题',
          align: "center",
          dataIndex: 'title'
        },
        {
          title: '展示图片',
          align: "center",
          dataIndex: 'imgUrl',
          scopedSlots: { customRender: 'imgSlot' }
        },
        {
          title: '剩余总库存',
          align: "center",
          dataIndex: 'stock'
        },
        {
          title: '商品状态',
          align: "center",
          dataIndex: 'status_dictText'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/mallBase/gmsGood/zyList",
        delete: "/mallBase/gmsGood/delete",
        deleteBatch: "/mallBase/gmsGood/deleteBatch",
        exportXlsUrl: "/mallBase/gmsGood/exportXls",
        importExcelUrl: "mallBase/gmsGood/importExcel",

      },
      dictOptions: {},
      cateId1s: [],
      cateId2s: []
    }
  },
  created () {
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    searchReset () {
      this.queryParam = {
        pcategoryId: undefined,
        categoryId: undefined
      }
      this.loadData()
    },
    open (type) {
      this.queryParam = {
        pcategoryId: undefined,
        categoryId: undefined
      }
      this.loadData()
      this.getcateId1s()
    },
    getcateId1s () {
      let self = this
      getAction("/mallBase/gmsCategory/oneList", { pid: '' }).then(res => {
        if (res.success) {
          this.cateId1s = res.result
        } else {
          this.$message.error(res.message)
        }
      })
    },
    getcateId2sChange (pid) {
      this.queryParam.categoryId = undefined
      this.getcateId2s(pid)
    },
    getcateId2s (pid) {
      let self = this
      if (pid) {
        getAction("/mallBase/gmsCategory/oneList", { pid: pid }).then(res => {
          if (res.success) {
            this.cateId2s = res.result
          } else {
            this.$message.error(res.message)
          }
        })
      } else {
        this.cateId2s = []
      }

    },
    setSelected () {
      this.pageCheckedKeys = []
      this.noPageCheckedKeys = []
      this.pageCheckedRows = []
      this.noPageCheckedRows = []
      for (let i = 0; i < this.checkedKeys.length; i++) {
        let isSelect = false
        for (let j = 0; j < this.dataSource.length; j++) {
          if (this.dataSource[j].itemCode == this.checkedKeys[i]) {
            isSelect = true
          }
        }
        if (isSelect) {
          this.pageCheckedKeys.push(this.checkedKeys[i])
          this.pageCheckedRows.push(this.checkedRows[i])
        } else {
          this.noPageCheckedKeys.push(this.checkedKeys[i])
          this.noPageCheckedRows.push(this.checkedRows[i])
        }
      }
      this.selectedRowKeys = this.pageCheckedKeys
    },
    initDictConfig () {
    }
  }
}
        </script>
<style scoped>
@import '~@assets/less/common.less';
</style>
